Skip to content

Add ChildWorkflowOptions support to WorkflowImplementationOptions (#2)#2887

Open
porunov wants to merge 1 commit into
temporalio:mainfrom
porunov:feature/child-workflow-options
Open

Add ChildWorkflowOptions support to WorkflowImplementationOptions (#2)#2887
porunov wants to merge 1 commit into
temporalio:mainfrom
porunov:feature/child-workflow-options

Conversation

@porunov

@porunov porunov commented May 25, 2026

Copy link
Copy Markdown

Fixes #2790

Tests are added to: ChildWorkflowOptionsInWorkflowImplementationOptionsTest.java

  • Add childWorkflowOptions map and defaultChildWorkflowOptions fields
  • Add setChildWorkflowOptions() and setDefaultChildWorkflowOptions() builder methods
  • Add getChildWorkflowOptions() and getDefaultChildWorkflowOptions() getters
  • Update SyncWorkflowContext to store and expose child workflow options
  • Update WorkflowInternal.newChildWorkflowStub() to merge predefined options
  • Add mergeChildWorkflowOptions() method to ChildWorkflowOptions.Builder
  • Add integration and unit tests

Potential documentation place: https://docs.temporal.io/develop/java/workflows/child-workflows (it could be something similar as activity options documentation).

Disclaimer: Code was Generated by Opus 4.6 in Copilot. Reviewed manually.

@porunov porunov requested a review from a team as a code owner May 25, 2026 20:56
@CLAassistant

CLAassistant commented May 25, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@porunov porunov force-pushed the feature/child-workflow-options branch from bd8e2d9 to 3295d53 Compare May 25, 2026 21:04

@maciejdudko maciejdudko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @porunov, thank you for your contribution. The code looks good, but the tests need to be improved before we can merge this - see comment.

Comment on lines +46 to +47
@Test
public void testDefaultChildWorkflowOptionsApplied() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test does not actually assert that the right options were used. Please rewrite it so that the child workflow only succeeds if the default options were correctly applied. I think checking its memo would be most straight forward.

Please also add a test that verifies default, not per-type child workflow options work too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @maciejdudko for pointing at it. There was a bug when the default options would overwrite per type options, but it's now fixed. Also added the tests as you requested. All tests are passing now. Let me know please if there are any other concerns with this PR.

@voplica-git voplica-git force-pushed the feature/child-workflow-options branch from 3295d53 to 948ecc8 Compare June 26, 2026 10:29
…plementationOptions

Fixes temporalio#2790

Allow predefining ChildWorkflowOptions on WorkflowImplementationOptions,
mirroring the existing ActivityOptions, LocalActivityOptions and
NexusServiceOptions support:

- Add setChildWorkflowOptions(Map) and setDefaultChildWorkflowOptions()
  builder methods, matching getters, and equals/hashCode/toString/
  toBuilder support on WorkflowImplementationOptions
- Expose the options through SyncWorkflowContext, served directly from
  the immutable WorkflowImplementationOptions
- Add ChildWorkflowOptions.Builder#mergeChildWorkflowOptions(): non-null
  override fields win, except contextPropagators lists are concatenated
  (matching ActivityOptions.Builder#mergeActivityOptions), the mutually
  exclusive searchAttributes/typedSearchAttributes are merged as one
  logical field so the merged options never carry both flavors, and
  VERSIONING_INTENT_UNSPECIFIED is treated as unset
- Resolve the predefined options for both typed and untyped child stubs
  (WorkflowInternal.newChildWorkflowStub and newUntypedChildWorkflowStub,
  so DynamicWorkflow parents are covered too) with the following
  precedence, highest to lowest, merged field by field: options passed
  to the stub creation method > per-type options (setChildWorkflowOptions)
  > default options (setDefaultChildWorkflowOptions)
- Keep child stub creation cost unchanged: the interface metadata is
  computed once and passed into ChildWorkflowInvocationHandler instead
  of being reflectively re-derived
- Keep the previous public WorkflowImplementationOptions constructor as
  a backward-compatible delegating overload
- Document the new behavior on the Workflow child stub factory methods
  and warn against predefining workflowId, which would be applied to
  every child of the matching scope

Fix child workflow options precedence: the predefined options were
merged in the wrong order, so when no options were passed to
newChildWorkflowStub the default options overrode the per-type options.
The default options have the lowest precedence and must never override
per-type options. The merge order is now correct, and the javadocs on
setChildWorkflowOptions and setDefaultChildWorkflowOptions describe the
actual precedence.

Tests:
- Verify the applied options through the child's memo in
  DefaultChildWorkflowOptionsSetOnWorkflowTest (covering default,
  per-type, explicit and field-level merge precedence for both typed
  and untyped stubs), so a test only passes if the expected options
  actually took effect
- Add an exhaustive unit test for
  ChildWorkflowOptions#mergeChildWorkflowOptions that exercises every
  field, plus dedicated tests for the search attribute flavors, context
  propagator concatenation and unspecified versioning intent

Signed-off-by: Oleksandr Porunov <alexandr.porunov@gmail.com>
@porunov porunov force-pushed the feature/child-workflow-options branch from 948ecc8 to 101bb90 Compare July 7, 2026 12:28
@porunov porunov requested a review from maciejdudko July 7, 2026 12:31
@porunov

porunov commented Jul 7, 2026

Copy link
Copy Markdown
Author

@maciejdudko I've rebased in from main branch. Would be great if you could check the PR again. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend WorkflowImplementationOptions with ChildWorkflowOptions

3 participants